import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import path from 'path';

export default defineConfig({
    base: "/", // 设置项目的基础路径
    plugins: [
        react(),
        tailwindcss(),
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, './src'),
            '@modules': path.resolve(__dirname, './node_modules'),
        },
    },
    server: {
        port: 3000,
        proxy: {
            '/api': {
                target: 'http://localhost:5000', // 后端服务器地址
                changeOrigin: true,
                secure: false,
            }
        },
    },
    build: {
        commonjsOptions: {
            include: [/node_modules/] // 确保commonjs模块被打包
        },
        chunkSizeWarningLimit: 2000,
        rollupOptions: {
            output: {
                manualChunks(id) {
                    if (id.includes('src/components')) {
                        //return 'components';
                    }

                    if (id.includes('src/pages')) {
                        //return 'pages';
                    }

                    if (id.includes('react') || id.includes('react-dom') || id.includes('react-router-dom') || id.includes("react-bootstrap")) {
                        return 'react';
                    }
                }
            }
        },
    },
    preview: {
        port: 3001,
        proxy: {
            '/api': {
                target: 'http://localhost:5000', // 后端服务器地址
                changeOrigin: true,
                secure: false,
            }
        }
    }
}); 